<?xml version="1.0" encoding="ISO-8859-1" ?>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>FFI page</title>
        
        <script src="jquery.js"></script>
 		<script src="jquery-ui.js"></script>
 		<link rel="stylesheet" type="text/css" href="jquery-ui.css"/>
 		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
 		<!-- <style media="screen" type="text/css">
			.table {
			  max-width: 100%;
			  background-color: transparent;
			  border-collapse: collapse;
			  border-spacing: 0;
			}
			
			.table {
			  width: 100%;
			  margin-bottom: 20px;
			}
			
			.table th,
			.table td {
			  padding: 8px;
			  line-height: 20px;
			  text-align: left;
			  vertical-align: top;
			  border-top: 1px solid #dddddd;
			}
			
			.table th {
			  font-weight: bold;
			}
			
			.table thead th {
			  vertical-align: bottom;
			}
			
			.table caption + thead tr:first-child th,
			.table caption + thead tr:first-child td,
			.table colgroup + thead tr:first-child th,
			.table colgroup + thead tr:first-child td,
			.table thead:first-child tr:first-child th,
			.table thead:first-child tr:first-child td {
			  border-top: 0;
			}
			
			.table tbody + tbody {
			  border-top: 2px solid #dddddd;
			}
			
			.table .table {
			  background-color: #ffffff;
			}
			
			.table-hover tbody tr:hover > td,
			.table-hover tbody tr:hover > th {
			  background-color: #f5f5f5;
			}
			.table-hover tbody tr.success:hover > td {
			  background-color: #d0e9c6;
			}
			.table-hover tbody tr.error:hover > td {
			  background-color: #ebcccc;
			}
			.table-hover tbody tr.warning:hover > td {
			  background-color: #E6F3FF;
			}
			.table-hover tbody tr.info:hover > td {
			  background-color: #c4e3f3;
			}

	
	  </style>   -->
    
    <script type="text/javascript">
       
      function myFunFFI(id2){
          if($('#'+id2.id).is(':checked'))
       	   $("#tf1").show();
     	    else $("#tf1").hide();
          
          var ansId0 = $('[name="ansId0"]:checked').val(); 
          var ansId1 = $('[name="ansId1"]:checked').val(); 
          var ansId2 = $('[name="ansId2"]:checked').val();
          $("#ffiStatus").html("<span class='label label-info'>FFI- unconfirmed</span>");
          var ansValSpe = (ansId0 =="No" || ansId1 =="No" || ansId2 =="No");
          if(ansValSpe)
          $("#ffiStatus").html("<span class='label label-info'>FFI- unconfirmed Pending supporting documents</span>");
          
      }
      
      function myFunFFIQ(){
          
          var ansId0 = $('[name="ansId0"]:checked').val(); 
          var ansId1 = $('[name="ansId1"]:checked').val(); 
          var ansId2 = $('[name="ansId2"]:checked').val();
          $("#ffiStatus").html("<span class='label label-info'>FFI- unconfirmed</span>");
          var ansValSpe = (ansId0 =="No" || ansId1 =="No" || ansId2 =="No");
          if(ansValSpe)
          $("#ffiStatus").html("<span class='label label-info'>FFI- unconfirmed Pending supporting documents</span>");
          
      }
      
      function myFunFFISQ(){
          
    	  var x1 = $("#ec2").text();
		 	 
      	 if(x1 == "Local FFIs"){
    			 var ansfId0 = $('[name="ansfId0"]:checked').val(); 
        		 var ansfId1 = $('[name="ansfId1"]:checked').val(); 
        		 var ansfId2 = $('[name="ansfId2"]:checked').val();
        		 var ansValFFISpeYes = (ansfId0 =="Yes" && ansfId1 =="Yes" && ansfId2 =="Yes");
        		 var ansValFFISpeNo = (ansfId0 =="No" && ansfId1 =="No" && ansfId2 =="No");
        		 $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Local unconfirmed<b/>");
       		 if(ansValFFISpeYes)
       			$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Local confirmed<b/>");    			 
       		 if(ansValFFISpeNo)
       			$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Local failed<b/>");              		 		               		
		 	 } 
      	
      	 if(x1 == "Nonreporting members of participating FFI groups"){
   			 var ansfId0 = $('[name="ansfId0"]:checked').val(); 
       		 var ansfId1 = $('[name="ansfId1"]:checked').val(); 
       		 var ansValNonreportingFFISpeYes = (ansfId0 =="Yes" && ansfId1 =="Yes");
       		 var ansValNonreportingFFISpeNo = (ansfId0 =="No" && ansfId1 =="No");
       		 $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Nonreporting members of PFFI unconfirmed</span>");
        		 if(ansValNonreportingFFISpeYes)
        			$("#ncsFfiSpe").html("<span class='label label-info'>Nonreporting members of PFFI confirmed</span>");    			 
        		 if(ansValNonreportingFFISpeNo)
        			$("#ncsFfiSpe").html("<span class='label label-info'>Nonreporting members of PFFI failed</span>");              		 		               		
   		 } 
		 	
		     if(x1 == "Qualified collective investment vehicles"){
   			 var ansfId0 = $('[name="ansfId0"]:checked').val(); 
       		 var ansfId1 = $('[name="ansfId1"]:checked').val();
       		 var ansfId2 = $('[name="ansfId2"]:checked').val();
       		 var ansfId3 = $('[name="ansfId3"]:checked').val();
       		 var ansValQualifiedFFISpeYes = (ansfId0 =="Yes" && ansfId1 =="Yes"  && ansfId2 =="Yes" && ansfId3 =="Yes");
       		 var ansValQualifiedFFISpeNo = (ansfId0 =="Yes" || ansfId1 =="Yes" || ansfId2 =="Yes");
       		 $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Qualified collective investment vehicles unconfirmed</span>");
    		 	if(ansValQualifiedFFISpeYes)
    				$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Qualified collective investment vehicles confirmed</span>");    			 
    		 	else if(ansValQualifiedFFISpeNo)
    				$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Qualified collective investment vehicles failed</span>");              		 		               		
		    }
		 
    		if(x1 == "Restricted Funds"){
	      			var ansfId0 = $('[name="ansfId0"]:checked').val();  
	          		var ansfId1 = $('[name="ansfId1"]:checked').val();  
	          		var ansfId2 = $('[name="ansfId2"]:checked').val();  
	          		var ansfId3 = $('[name="ansfId3"]:checked').val();
	          		var ansfId4 = $('[name="ansfId4"]:checked').val();  
	          		var ansfId5 = $('[name="ansfId5"]:checked').val();
	          		var ansfId6 = $('[name="ansfId6"]:checked').val();
	          		var ansfId7 = $('[name="ansfId7"]:checked').val();
	          		var ansfId8 = $('[name="ansfId8"]:checked').val();
	          		 
	          		var ansValRestrictedFFISpeYes = (ansfId0 =="Yes" && ansfId1 =="Yes"  && ansfId2 =="Yes" 
	          										&& ansfId3 =="Yes" && ansfId4 =="Yes" && ansfId5 =="Yes" 
	          										&& ansfId6 =="Yes" && ansfId7 =="Yes" && ansfId8 =="Yes");
	          		var ansValRestrictedFFISpeNo = (ansfId0=="No" || ansfId1=="No" || ansfId2=="No" || ansfId4=="No");
	          		$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Restricted Funds unconfirmed</span>");
   		     	if(ansValRestrictedFFISpeYes)
   					$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Restricted Funds confirmed</span>");    			 
   		     	if(ansValRestrictedFFISpeNo)
   					$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Restricted Funds  - failed</span>");              		 		               		
		    }
    		
    		if(x1 == "Qualified credit card issuers"){
   			var ansfId0 = $('[name="ansfId0"]:checked').val();  
       		var ansfId1 = $('[name="ansfId1"]:checked').val();  
       		var ansValQualifiedCreditFFISpeYes = (ansfId0 =="No" && ansfId1 =="Yes");
       		var ansValQualifiedCreditFFISpeNo = (ansfId0=="Yes" && ansfId1=="No");
       		
       		$("#ncsFfiSpe").html("<span class='label label-info'>FFI Qualified credit card issuers unconfirmed</span>");
		     	if(ansValQualifiedCreditFFISpeYes)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI: Qualified credit card issuers confirmed</span>");    			 
		     	if(ansValQualifiedCreditFFISpeNo)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI: Qualified credit card issuers failed</span>");              		 		               		
	    	}
    		
    		if(x1 == "Sponsored investment entities and controlled foreign corporations"){
   			var ansfId0 = $('[name="ansfId0"]:checked').val();  
       		var ansfId1 = $('[name="ansfId1"]:checked').val();  
       		var ansfId2 = $('[name="ansfId2"]:checked').val(); 
       		var ansValYes = (ansfId0 =="Yes" && ansfId1 =="Yes" && ansfId2 =="Yes");
       		var ansValNo = (ansfId0=="No" && ansfId1=="No" && ansfId2 =="No");
       		
       		$("#ncsFfiSpe").html("<span class='label label-info'>Sponsored investment/controlled foreign unconfirmed<b/>");
		     	if(ansValYes)
					$("#ncsFfiSpe").html("<span class='label label-info'>Sponsored investment/controlled foreign confirmed<b/>");    			 
		     	if(ansValNo)
					$("#ncsFfiSpe").html("<span class='label label-info'>Sponsored investment/controlled foreign failed<b/>");              		 		               		
	    	}
    		
    		
    		if(x1 == "Certified deemed compliant FFI- Nonregistering Local Bank"){
   			var ansfId0 = $('[name="ansfId0"]:checked').val();  
       		var ansfId1 = $('[name="ansfId1"]:checked').val();  
       		var ansfId2 = $('[name="ansfId2"]:checked').val(); 
       		var ansValYes = (ansfId0 =="Yes" && ansfId1 =="No" && ansfId2 =="Yes");
       		var ansValNo = (ansfId0=="No" && ansfId1=="Yes" && ansfId2 =="No");
       		
       		$("#ncsFfiSpe").html("<span class='label label-info'>FFI- Nonregistering Local Bank unconfirmed<b/>");
		     	if(ansValYes)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI- Nonregistering Local Bank confirmed<b/>");    			 
		     	if(ansValNo)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI- Nonregistering Local Bank failed<b/>");              		 		               		
	    	}
    		
    		if(x1 == "Certified Deemed Compliant FFI - Low Value Account"){
   			var ansfId0 = $('[name="ansfId0"]:checked').val();  
       		var ansfId1 = $('[name="ansfId1"]:checked').val();  
       		var ansfId2 = $('[name="ansfId2"]:checked').val(); 
       		var ansValYes = (ansfId0 =="No" && ansfId1 =="Yes" && ansfId2 =="No");
       		var ansValNo = (ansfId0=="Yes" && ansfId1=="No" && ansfId2 =="Yes");
       		
       		$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Low Value Account unconfirmed<b/>");
		     	if(ansValYes)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Low Value Account confirmed<b/>");    			 
		     	if(ansValNo)
					$("#ncsFfiSpe").html("<span class='label label-info'>FFI - Low Value Account failed<b/>");              		 		               		
	    	}
          
      }
      
      
      function func1(){
    	  var x1 = $("#eccfs1 :selected").text();
    	  var x2 = $("#eccfs1 :selected").val();
    	  $("#ec2").html("<span class='label label-info'>"+x1+"</span>");
    	  //$("#ncs2").text(x1);
    	  if(x1=='Local FFIs'){
    		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Local unconfirmed<b/>");
    	  }
    	  if(x1=='Nonreporting members of participating FFI groups'){
    		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Nonreporting members of PFFI unconfirmed<b/>");
    	  }
    	  if(x1=='Qualified collective investment vehicles'){
    		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Qualified collective investment vehicles unconfirmed<b/>");
    	  }
    	  if(x1=='Restricted Funds'){
    		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Restricted Funds unconfirmed<b/>");
    	  }
    	  if(x1=='Qualified credit card issuers'){
    		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI Qualified credit card issuers unconfirmed<b/>");
    	  }
    	  if(x1 == "Sponsored investment entities and controlled foreign corporations"){
   		  $("#ncsFfiSpe").html("<span class='label label-info'>Sponsored investment/controlled foreign unconfirmed<b/>");
   		  }
   		  if(x1 == "Certified deemed compliant FFI- Nonregistering Local Bank"){
   		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI- Nonregistering Local Bank unconfirmed<b/>");
   		  }
   		  if(x1 == "Certified Deemed Compliant FFI - Low Value Account"){
   		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Low Value Account unconfirmed<b/>");
   		  }
    	  
    	  $('#snqffi').empty();
    	  $.get( "findQuesByCategory",{category : x1},function( data ) {
    		  $('#snqffi').append('<input type="hidden" name="quessize" value="'+data.length+'" id="quessize"/>');
			  if(data.length==1 && data[0].name==""){
				  $('#snqffi').append('<tr class="info" width="100%"><td colspan="2"><b>No Question found.</b></td></tr>');
				  $('#formSubmit').hide();
			  }
			  else{
				  $('#formSubmit').show();
				  $('#quesnum').val(data.length);
    		  $.each(data, function(i, item) {
    		  var hidf= item.id;
			  var hiddf= "quesfId"+i;
			  var ansId= "ansfId"+i;
			  var qidno= "qs"+ item.id +"_no";
			  
	 		  $('#snqffi').append('<tr class="info" width="100%"><td width="70%"><label for="'+item.id+'">'+item.name+'</label></td><td width="30%"><div id="'+item.id+'"><input type="hidden" name="'+hiddf+'" value="'+hidf+'" id="'+hiddf+'"/><input type="radio" value="Yes" id="'+item.id+'" name="'+ansId+'" onclick="myFunFFISQ()" />Yes <input type="radio" value="No" id="'+item.id+'_no" name="'+ansId+'" onclick="myFunFFISQ()" />No <input type="radio" value="Don'+"'"+'t Know" id="'+item.id+'_dn" name="'+ansId+'" onclick="myFunFFISQ()" checked/>Don'+"'"+'t Know</td></tr>');
			 
 			 });
		   }
    	});
      }
      
      $(document).ready(function() {
    	 var m= '${mode}';
    	 var cats = '${cats}';
    	 if ($('#chgCatFFI').is(":checked")) $('#chgCatF').show();
   	     else $('#chgCatF').hide();
    	 $('#chgCatFFI').click(function(){
    		 if ($('#chgCatFFI').is(":checked")) $('#chgCatF').show();
       	     else $('#chgCatF').hide();
    	 });
    	// alert("---->"+m);
    	  //alert( m == 'showc')
    	  if( m == 'showc' ){
    		  $("#eC").show();
        	  $("#enC").show();
        	  $("#sQ").show();
        	  $("#sNQ1").show();
        	  $("#ec2").html("<span class='label label-info'>"+cats+"</span>");
        	  if(cats=='Local FFIs'){
        		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Local unconfirmed</span>");
        	  }
        	  if(cats=='Nonreporting members of participating FFI groups'){
        		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Nonreporting members of PFFI unconfirmed</span>");
        	  }
        	  if(cats=='Qualified collective investment vehicles'){
        		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Qualified collective investment vehicles unconfirmed</span>");
        	  }
        	  if(cats=='Restricted Funds'){
        		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Restricted Funds unconfirmed</span>");
        	  }
        	  if(cats=='Qualified credit card issuers'){
        		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI Qualified credit card issuers unconfirmed</span>");
        	  }
        	  if(cats == "Sponsored investment entities and controlled foreign corporations"){
       		  $("#ncsFfiSpe").html("<span class='label label-info'>Sponsored investment/controlled foreign unconfirmed</span>");
       		  }
       		  if(cats == "Certified deemed compliant FFI- Nonregistering Local Bank"){
       		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI- Nonregistering Local Bank unconfirmed</span>");
       		  }
       		  if(cats == "Certified Deemed Compliant FFI - Low Value Account"){
       		  $("#ncsFfiSpe").html("<span class='label label-info'>FFI - Low Value Account unconfirmed</span>");
       		  }
        	  $("#signInFFI").hide();
    	  }
    	  else {
    		  $("#eC").hide();
        	 $("#enC").hide();
        	  $("#sQ").hide();
        	  $("#sNQ1").hide();
        	  $("#signInFFI").show();
    	  }
    	  
    	  $("#accordion, #accordion1").accordion({
   		  // event: "mouseover",
	    	   collapsible: true,
	    	   heightStyle: "content"
   	      });
    	  
    	  var sid = '${sid}';
    	  var customerFields = [ "Name of EntityCustomer", "TIN","Country of Issuance", "Country of Incorporation","LEI","Aggregate Balance Expected","Investment Income as Ratio of Gross Income",
     	                     	"Assets Quarterly Investment Income", "Incorporation Date", "Bankruptcy Filing Date", "US Owners Share Distribution", "US Owners Share Value in Dollars",
     	                    	"Electronic Account Number", "Passive Income of EAG","Gross Income of EAG", "Total Assests Entity", "Total Assests EAG", "Chapter 4 Status", "Status",
     	                    	"Fatca Status", "Audit Log", "More Info", "Is Info Missing","Is DocMissing",  "Created By", "Updated By", "Creation Date", "Modification Date"];
     	  $.get( "users/findCustomerById", {id: sid},function( data ) {	
     		  var i=0;
     		  $.each(data, function(key, val) {
     			  var bvalue = key!='id' && key!='customerDocuments' && key!='businessNature' && key!='stocksDistribution' && key!='regulators' && key!='restrictedDistributor'
     				  && key!='market' && key!='sourceIncome' && key!='eagPassiveIncome' && key!='memberStatus' && key!='locations' && key!='contact';
     		        if(bvalue){
     		        	if(val==null) val="";
     		            if(key=='chapter4status')
       		            $('#clientInfo').append('<tr class="info" ><td style="width:260px">'+ customerFields[i] + ' : </td><td><b>' + val.split("_")[1] + '</b></td></tr>');
       		        	else $('#clientInfo').append('<tr class="info" ><td style="width:260px">'+ customerFields[i] + ' : </td><td><b>' + val + '</b></td></tr>');
     		            i++;
     		        }
     		    });
     	  });
      $('#businessNatureDialog').dialog({autoOpen:false});
   	  $("#businessNatureDialogLink").click(function(){
			   $('#businessNatureDialog').dialog('open');
			   $('#businessNatureDialog').dialog({
	    	        modal: true,	    	              
	    	        height: 300,
	    	        width: 665,
	    	        title: 'Business Nature Page'
	    	    });
	      });
   	  $.get("customer/getAllBusinessNature",{id:sid},function(data) {
				if(data.length>0)
				$.each(data,function(i, item) {
					$("#myBodyBN").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.businessActivity+"</td><td>"+item.entityName+"</td><td>"+item.industryClass+"</td></tr>");
				});
				else
					$("#myBodyBN").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
		  });
   	  
   	  
   	  $('#eagMemberStatusDialog').dialog({autoOpen:false});
   	  $("#eagMemberStatusLink").click(function(){
   		   $('#eagMemberStatusDialog').dialog('open');
			   $('#eagMemberStatusDialog').dialog({
	    	        modal: true,
	    	        height: 300,
	    	        width: 665,
	    	        title: 'EAG Member Status Page'
	    	    });
	      });
   	  $.get("customer/getAllEAGMemberStatus",{id:sid},function(data) {
   		  if(data.length>0)
				$.each(data,function(i, item) {
					$("#myBodyMS").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.memberName+"</td><td>"+item.status+"</td></tr>");
				});
   		  else
					$("#myBodyMS").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
		  });
  	  
   	  
   	  $('#eagPassiveIncomeDialog').dialog({autoOpen:false});
  	      $("#eagPassiveIncomeLink").click(function(){
  	    	   $('#eagPassiveIncomeDialog').dialog('open');
			   $('#eagPassiveIncomeDialog').dialog({
	    	        modal: true,
	    	        height: 300,
	    	        width: 665,
	    	        title: 'EAG Passive Income Page'
	    	    });
	      });
  	      
  	      $.get("customer/getAllEAGPassiveIncome",{id:sid},function(data) {
	   	     if(data.length>0)
				$.each(data,function(i, item) {
					$("#myBodyPI").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.sourceName+"</td><td>"+item.percentage+"</td></tr>");
				});
	   	     else
					$("#myBodyPI").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
			
		  });
  	      
  	      $('#exchangeMarketDialog').dialog({autoOpen:false});
  	      $("#exchangeMarketLink").click(function(){
  	    	   $('#exchangeMarketDialog').dialog('open');
			   $('#exchangeMarketDialog').dialog({
	    	        modal: true,
	    	        height: 300,
	    	        width: 665,
	    	        title: 'Exchange Market Page'
	    	    });
         });
  	      
  	      $.get("customer/getAllExchangeMarket",{id:sid},function(data) {
	   	     if(data.length>0)
				$.each(data,function(i, item) {
					$("#myBodyEM").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.marketName+"</td><td>"+item.ticket+"</td></tr>");
				});
	   	     else
					$("#myBodyEM").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
			
		  });
  	      
  	    
  	   	   $('#locationsDialog').dialog({autoOpen:false});
  		      $("#locationsLink").click(function(){
  		    	   $('#locationsDialog').dialog('open');
  				   $('#locationsDialog').dialog({
  		    	        modal: true,
  		    	        height: 300,
  		    	        width: 665,
  		    	        title: 'Locations Page'
  		    	    });
  	       });
  		      
  		      $.get("customer/getAllLocations",{id:sid},function(data) {
  		   	     if(data.length>0)
  					$.each(data,function(i, item) {
  						$("#myBodyL").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.city+"</td><td>"+item.ticket+"</td></tr>");
  					});
  		   	     else
  						$("#myBodyL").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
  				
  			  });
  		      
  		      
  		      $('#regulatorsDialog').dialog({autoOpen:false});
  	   	      $("#regulatorsLink").click(function(){
  	   	    	   $('#regulatorsDialog').dialog('open');
  				   $('#regulatorsDialog').dialog({
  		    	        modal: true,
  		    	        height: 300,
  		    	        width: 665,
  		    	        title: 'Regulators Page'
  		    	    });
  	          });
  	   	      
  	   	      $.get("customer/getAllRegulators",{id:sid},function(data) {
  		   	     if(data.length>0)
  					$.each(data,function(i, item) {
  						$("#myBodyR").append("<tr  class='warning'><td>"+ item.id+ "</td><td>"+item.regulatorName+"</td><td>"+item.country+"</td></tr>");
  					});
  		   	     else
  						$("#myBodyR").append("<tr  class='warning'><td colspan='4'><center><b>No data found yet.</b></center></td></tr>");
  				
  			  });
   	  
   	    	  
    	  
    	  $.get( "users/findDocumentByCustId", {id: sid},function( data ) {	
    		  $('#docInfo').append('<span class="label label-info" style="font-size:12px"> Documents Uploaded : </span>');
    		  if(data.length==0) $('#docInfoTbl').append('<tr class="info"><td colspan="2"><b>No document attached.</b></td></tr>');
    		  else
    		  $.each(data, function(i,item) {
    			  var s=item.filePath;
    			  $('#docInfoTbl').append('<tr class="info"><td>'+item.doc.name+' : </td><td><a href="downloadFileStatus?filePath='+s+'&fileName='+item.fileName+'">' + item.fileName + '</a></td></tr>');
    	    		 
    		  });
    	 });
    	  
    	  
    	  
    	  
    	  if( m != 'showc' ){  
           	  $.get( "question/fetchFfeQuestions",function( data ) {	
         		 // console.log('data : '+data.length);
         		 // if(data.length==0) $('#clientInfo').append('No document attached.');
         		 // else
         		 $.each(data, function(i, item) {
         			//  var qid= "question"+ item.name.split(". ")[0];
         			 // var qidno= "question"+ item.name.split(". ")[0]+"_no";
         			  var hidf= item.id;
         			  var hiddf= "quesId"+i;
         			  var ansId= "ansId"+i;
         			  var qidno= "qs"+ item.id +"_no";
         			  var qiddno= "qs"+ item.id +"_dno";
         			  //$('#ffiFormd').append('<div class="control-group"><label class="control-label login-label " for="'+item.id+'">'+item.name+'</label>');
         			  
         			  if(i==0) {
         				  $('#ffiFormd').append('<tr class="info" width="100%"><td width="70%"><label for="'+item.id+'">'+item.name+'</label></td><td width="30%"><div id="'+item.id+'"><input type="hidden" name="'+hiddf+'" value="'+hidf+'" id="'+hiddf+'"/><input type="radio" value="Yes" id="'+item.id+'" name="'+ansId+'"  onclick="myFunFFI('+qidno+')" checked/>Yes <input type="radio" value="No" id="'+qidno+'" name="'+ansId+'"  onclick="myFunFFI('+qidno+')" />No <input type="radio" value="Don'+"'"+'t Know" id="'+qiddno+'" name="'+ansId+'"  onclick="myFunNFFE('+qiddno+')" checked/>Don'+"'"+'t Know <div id="tf1"><input type="text" name="explanation" id="explanation" placeholder="Explanation"/></div></td></tr>');
         				  $("#tf1").hide();
         			  }
         			  else $('#ffiFormd').append('<tr class="info" width="100%"><td width="70%"><label for="'+item.id+'">'+item.name+'</label></td><td width="30%"><div id="'+item.id+'"><input type="hidden" name="'+hiddf+'" value="'+hidf+'" id="'+hiddf+'"/><input type="radio" value="Yes" id="'+item.id+'" name="'+ansId+'" onclick="myFunFFIQ()" checked/>Yes <input type="radio" value="No" id="'+item.id+'_no" name="'+ansId+'" onclick="myFunFFIQ()" />No <input type="radio" value="Don'+"'"+'t Know" id="'+qiddno+'" name="'+ansId+'"  onclick="myFunFFIQ()" checked/>Don'+"'"+'t Know</td></tr>');
         		 });
           	 });
        	 }
        	 else{
        		 var cust = '${sid}';
        		 $.get( "users/findCustomerById", {id: cust},function( data ) {
       			  $('#ffiStatus').html("<span class='label label-info'>"+data.fatcaStatus+"</span>");
       		     });
        		 
       		  $.get( "getResponseFFI",{id:cust},function( data ) {
       			  $( "#ffiFormd" ).removeClass( "panel panel-info" );
  			      $('#ffiFormd').append('<table class="table table-hover" id="tabIdF" style="width:650px"></table>');
       			  //console.log("------>"+data);
       			  $.each(data, function(i, item) {
       				  var ansId= "ansId"+i;
       				  //$('#ffiFormd').append('<br/><div class="control-group" style="float:left"><label class="control-label login-label" > . '+item.question.name+'</label></div>');
       				  if(i==0){
       					  if(item.answer == "Y")
               				  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>Yes</span></td></tr>');
       					if(item.answer == "N"){
               					  var x;
               					  if(item.comment != "") x = item.comment.split(":")[1].trim(); 
               					  else x="";
               					  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>Yes</b>&nbsp;&nbsp;<b>Explanation : '+x+'</b></td></tr>'); 
               				  }
       					if(item.answer == "D")
             				  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>Don'+"'"+'t Know</b></td></tr>');	  	  
           				  
       				  }else{
       					   if(item.answer == "Y")
           				  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>Yes</b></td></tr>');
       					if(item.answer == "N")
           					  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>No</b></td></tr>');
       					if(item.answer == "D")
         					  $('#tabIdF').append('<tr class="info" width="100%"><td width="60%">'+item.question.name+'</td><td width="40%">&nbsp;&nbsp;<b>Don'+"'"+'t Know</b></td></tr>');
       				  }
       				  });
       		  });
        	 }
     		 
    	  var cust = '${sid}';
    	  $.get( "users/getListOfFFICategory",{id:cust},function( data ) {
    		  var x = '<div class="controls" id="eccsfId"><select id="eccfs1" name="eccfs1">';
			  $.each(data, function(i, item) {
				  x += '<option value='+item[0]+'>'+item[1]+'</option>'; 
			  });
			  x += '</select></div>';
			  $('#eccfs').append(x);
    	  });
    	  
    	  
    	 /*  $.get( "findAllCheckers",function( data ) {
    		  var x = '<div class="controls" id="checkerListIdf"><select id="checkerListf" name="checkerListf">';
			  $.each(data, function(i, item) {
				  x += '<option value='+item.id+'>'+item.firstname+'</option>'; 
			  });
			  x += '</select></div>';
			  $('#checkerListffi').append(x);
    	  }); */
    	  
    	  var cat = '${cats}';
    	  $.get( "findQuesByCategory",{category : cat},function( data ) {
    		  $('#snqffi').append('<input type="hidden" name="quessize" value="'+data.length+'" id="quessize"/>');
			  if(data.length==1 && data[0].name==""){
				  $('#snqffi').append('<tr class="info" width="100%"><td colspan="2"><b>No Question found.</b></td></tr>');
				  $('#formSubmit').hide();
			  }
			  else{
				  $('#formSubmit').show();
				  $('#quesnum').val(data.length);
    		  $.each(data, function(i, item) {
    		  var hidf= item.id;
			  var hiddf= "quesfId"+i;
			  var ansId= "ansfId"+i;
			  var qidno= "qs"+ item.id +"_no";
			  var ansIdno= "ansfId"+i+"_no";
			  var ansIdyes= "ansfId"+i+"_yes";
			  var ansIddn= "ansfId"+i+"_dn";
			 // var ansIdyes= "qs"+ item.id +"_no";
			  
			  
	 			  $('#snqffi').append('<tr class="info" width="100%"><td width="70%"><label for="'+item.id+'">'+item.name+'</label></td><td width="30%"><div id="'+item.id+'"><input type="hidden" name="'+hiddf+'" value="'+hidf+'" id="'+hiddf+'"/><input type="radio" value="Yes" id="'+ansIdyes+'" name="'+ansId+'" onclick="myFunFFISQ()" />Yes <input type="radio" value="No" id="'+ansIdno+'" name="'+ansId+'"  onclick="myFunFFISQ()" />No<input type="radio" value="Don'+"'"+'t Know" id="'+ansIddn+'" name="'+ansId+'"  onclick="myFunFFISQ()" checked/>Don'+"'"+'t Know</td></tr>');
	    		  
			 
 			 });
			  }
    	  });
    	  
    	  
    	  $("#signInFFI").click(function() {
    		 /*  var ansId0 = $('[name="ansId0"]:checked').val();
    		  var ansId1 = $('[name="ansId1"]:checked').val();
    		  var ansId2 = $('[name="ansId2"]:checked').val();
    		  var ansValFfi = (ansId0=="Yes" && ansId1=="Yes" && ansId2=="Yes"); */
    		  
    		  var qs = $("#ffiStatus").text();
    		  //alert(":: qs :: "+qs);
    		  $('[name="fatcaStatusFFI"]').val(qs);
    		  /* $('[name="fatcaStatusFFI"]').val("FFI- unconfirmed");
    		  if(!ansValFfi){
    			  $('[name="fatcaStatusFFI"]').val("FFI- unconfirmed Pending supporting documents");    			 
    		  } */
    		  $("#ffiForm").submit(function() {
                	$("#ffiForm").attr("action", "saveMakerFFIAnswers");
    		});
    		  
  		});
    	  
    	  
    	  
    	  
    	   $("#eccsFFIForm").submit(function() {
    		    var ecsffi = $('[name="entityClassificationStatus"]').val();
    		if(ecsffi == "Not_Approved"){
    			//var cust = '${sid}';
    			//$("#eccsFFIForm").attr("action", "findCustomerById?id="+cust);
    			$("#eccsFFIForm").attr("action", "success-login");
    		}
    		if(ecsffi == "Missing_Info"){
    			var cust = '${sid}';
    			$("#eccsFFIForm").attr("action", "findCustomerById");
    		}
    		if(ecsffi == "Approved"){
    			var quesnum = $('[name="quesnum"]').val();
             	var custID = $('[name="custID"]').val();
             	//alert("----->"+quesnum);
             	//alert("----->"+custID);
             	var xy = [];
             	 for (var i = 0; i < quesnum; i++) {
             		 var q="quesfId"+i;
             		 var a="ansfId"+i;
             		 var qv = $('[name="'+q+'"]').val();
             		 var av = $('[name="'+a+'"]:checked').val();
             		 var obj = {q : qv, a: av};
             		//alert("---->"+qv);
             		//alert("---->"+av);
             		 xy.push(obj);
             	}
             	 
             	 
	       		
       		var ncsFfiSpe = $("#ncsFfiSpe").text();
    		y={id:custID,fatcaStatusSpe:ncsFfiSpe,name:xy};
    		$.ajax({
	    		headers: { 
	    		        'Accept': 'application/json',
	    		        'Content-Type': 'application/json; charset=utf-8' 
	    		},
	            type: "POST",
	            url: "saveSpecificFFIAnswers",
	            contentType: "application/json; charset=utf-8",
	            data: JSON.stringify(y),
	            //data:y,
	            async: false,    //Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation
	            cache: false,    //This will force requested pages not to be cached by the browser          
	            processData:false,
	            success: function(resposeJsonObject){ 
	            	$("#eccsFFIForm").attr("action", "success-login");
	            }
	        });
	        }
  		}); 
    	});
    </script>
</head>
    <body>
<div style=" height:400px;overflow:scroll;overflow-x:hidden;">

        <div style="width:56%;float:left;height:290px;">
        
        <div id="accordion" style="width:700px;">
        
<h3>Initial Set of FFI Questions</h3>
<div style="height:230px">

<div style="float:left;font-size:20px;" ><span class="label label-info">FFI Eligibility Status : </span></div><div style="float:left;font-size:20px" id="ffiStatus"><span class="label label-info">FFI - unconfirmed</span></div>
<br/><br/>
<form class="form-horizontal" name="ffiForm" id="ffiForm" method="get">
 <input type="hidden" name="custID" value="${sid}" id="custQuesId"/>
<input type="hidden" name="catID" value="${cats}" id="catID"/>
<input type="hidden" name="fatcaStatusFFI" value="" id="fatcaStatusFFIId"/>

<!-- <div class="panel panel-info">

<div class="panel-body"  id="ffiFormd">
</div>
</div> -->
<table class="table table-hover" id="ffiFormd" style="width:600px"></table>
 <div class="control-group"><div class="controls"><input type="submit"  id="signInFFI" value="Proceed" class="button"/>
 </div></div> 	
			  </form>
</div>
<h3 id="eC">Entity Classification</h3>
<div id="enC">
<div id="ec1" style="float:left;font-size:20px"><span class='label label-info'>Entity Classification : </span></div><div id="ec2" style="float:left;font-size:20px"></div>
<br/><br/>
 <table class="table table-hover" id="nffeFormd" style="width:600px">
  <tr class="info" style="width:100%"><td><input type="checkbox" name="chgCatFFI" id ="chgCatFFI" value="Yes"/>Do you want to change the Category? </td></tr>
  <tr class="info" style="width:100%">
	  <td>
		  <div id="chgCatF">
			    <div>
				    <form id="eccsForm">
				        <input type="hidden" name="custID" value="${sid}" id="custQuesId"/>  
				        <div  id="eccfs"></div>
				        <div><div><input type="button"  id="signIneccs" value="Confirm" onclick="func1()" class="button"/></div></div>
			        </form> 
				</div>
		  </div>
	  </td>
  </tr>
 </table>
<br/>
</div>
<h3  id="sQ">Specific FFI Questions</h3>
<div id="sNQ1" style="overflow-y: scroll; height:200px;">
<div id="ncs1" style="float:left;font-size:20px"><span class='label label-info'>FFI Classification Status: </span></div>
<div id="ncsFfiSpe" style="float:left;font-size:20px"></div>

<br/>
<br/>
<br/>
<div class="control-group">
				  <div class="controls">
					<!-- <label class="checkbox"> <input type="checkbox" disabled> Remember me
					</label><br> -->
					<form id="eccsFFIForm">
					<input type="hidden" name="id" value="${sid}" id="custQuesId"/>  
			         <input type="hidden" name="custID" value="${sid}" id="custQuesId"/>  
			         <input type="hidden" name="quesnum" value="" id="quesnum"/>
			        <!-- <div class="panel panel-info">
			        <div class="panel-body" id="snqffi">
                    </div>
			        </div> -->
			        <table class="table table-hover" id="snqffi" style="width:600px"></table>
			        <br/>
			        <div class="control-group"><div class="controls">
			        <!-- <div><div style="float:left">Assigned to : </div><div id="checkerListffi" style="float:left"></div></div> -->
			        <div id="formSubmit">Status : <select name="entityClassificationStatus" id="entityClassificationStatus">
					  <option value="Approved">Approved</option>
					  <option value="Not_Approved">Not Approved</option>
					  <option value="Missing_Info">Missing Information</option>
					</select> 
			        <input type="submit"  id="signIneccsFFI" value="Confirm" class="button" />
			        </div></div></div>
			        </form> 
				  </div>
				</div>
</div>
</div>
</div>
<div style="width:33%;float:left;">
<div id="accordion1" style="width:491px;">
<h3>Client Information</h3>
<div style="overflow-y: scroll; height:400px;">
 <table class="table table-hover" id="clientInfo" style="width:450px">
 </table>
</div>
<h3>Additional Fields</h3>
<div id="additionalFields" style="overflow-y: scroll; height:250px;width:405px;" >
                     <table class="table table-hover">
                      <tr class="info"><td><a href="#" id="businessNatureDialogLink" title="Click here to open Business Nature Dialog"> Business Nature</a></td></tr>
                      <tr class="info"><td><a href="#" id="eagMemberStatusLink" title="Click here to open EAG Member Status Dialog"> EAG Member Status</a></td></tr>
                      <tr class="info"><td><a href="#" id="eagPassiveIncomeLink" title="Click here to open EAG Passive Income Dialog"> EAG Passive Income</a></td></tr>
                      <tr class="info"><td><a href="#" id="exchangeMarketLink" title="Click here to open Exchange Market Dialog"> Exchange Market</a></td></tr>
                      <tr class="info"><td><a href="#" id="locationsLink" title="Click here to open Locations Dialog"> Locations</a></td></tr>
                      <tr class="info"><td><a href="#" id="regulatorsLink" title="Click here to open Regulators Dialog"> Regulators</a></td></tr>
                    </table>
                <div id="businessNatureDialog">
	                <table id="myTable" class="table table-hover" align="center">
						
							<tr>
							    <th>Id</th>
								<th>Business Activity</th>
								<th>Entity Name</th>
								<th>Industry Class</th>
							</tr>
						
						<tbody id="myBodyBN">
	
						</tbody>
					</table>
                </div>
                <div id="eagMemberStatusDialog">
	                <table id="myTableMS" class="table table-hover" align="center">
							
								<tr>
								    <th>Id</th>
									<th>Member Name</th>
								    <th>Status</th>
								</tr>
							
							<tbody id="myBodyMS">
		
							</tbody>
					</table>
                </div>
                <div id="eagPassiveIncomeDialog">
	                <table id="myTablePI" class="table table-hover" align="center">
								
									<tr>
									    <th>Id</th>
										<th>Source Name</th>
							            <th>Percentage</th>
									</tr>
								
								<tbody id="myBodyPI">
			
								</tbody>
					</table>
                </div>
                 <div id="exchangeMarketDialog">
	                <table id="myTableEM" class="table table-hover" align="center">
								
									<tr>
									    <th>Id</th>
										<th>Market Name</th>
							            <th>Ticket</th>
									</tr>
								
								<tbody id="myBodyEM">
			
								</tbody>
					</table>
                </div>
                <div id="locationsDialog">
	                <table id="myTableL" class="table table-hover" align="center">
								
									<tr>
									    <th>Id</th>
										<th>City</th>
							            <th>Country</th>
									</tr>
								
								<tbody id="myBodyL">
			
								</tbody>
					</table>
                </div>
                
                 <div id="regulatorsDialog">
	                <table id="myTableR" class="table table-hover" align="center">
								
									<tr>
									    <th>Id</th>
										<th>Regulator Name</th>
							            <th>Country</th>
									</tr>
								
								<tbody id="myBodyR">
			
								</tbody>
					</table>
                </div>
</div>
<h3>Document Information</h3>
<div>
 <div id="docInfo"></div>
 <br/><br/>
 <table class="table table-hover" id="docInfoTbl"></table>
</div>
<%-- <h3>Missing Information</h3>
<div id="missingInfo">
<form action="" id="missingInfoForm">
<input type="checkbox" name="missingInfo" id="missingInfo" value="info"/>Missing Information <br/>
<input type="checkbox" name="missingDoc" id="doc" value="Car"/>Missing Documents<br/><br/>
<textarea id="moreInfo" rows="4" cols="50"> </textarea><br/>
<input type="submit" value="Submit"/>
</form>
</div> --%>
</div>
</div>
<div style="width:10%;float:left;">
<div style="float:right">
<form action="success-login">
    <button type='submit' class='btn btn-default' title='Close Current Tab'><span class='glyphicon glyphicon-remove'></span></button>
</form>
</div>
</div>
</div>
        <!--<button onclick="answerMe();">Answer Me</button>-->
    </body>
</html>